﻿/*********************************************************************************
 *Author:         OnClick
 *Version:        1.0
 *UnityVersion:   2018.3.11f1
 *Date:           2019-04-15
 *Description:    IFramework
 *History:        2018.11--
*********************************************************************************/
using System.IO;
using UnityEngine;

namespace IFramework
{
    public class ABCollectWindowBottom : IEditorGUI
    {
        public override void OnGUI(Rect rect, Rect worldRect)
        {
            base.OnGUI(rect, worldRect);
            DrawArea(() => {
                Space(10);
                Button((bo) =>
                {
                    if (bo) ABCollectWindow.colletors.Add(new ABCollectViewItem());
                }, "Add Collecter");
                DrawHorizontal(() =>
                {
                    Button((bo) =>
                    {
                        if (bo)
                            for (int i = ABCollectWindow.colletors.Count - 1; i >= 0; i--)
                                if (ABCollectWindow.colletors[i].Selected == true)
                                    ABCollectWindow.colletors.RemoveAt(i);
                    }, "Remove Choosed");
                    Button((bo) =>
                    {
                        if (bo)
                            for (int i = ABCollectWindow.colletors.Count - 1; i >= 0; i--)
                                if (ABCollectWindow.colletors[i].Selected == false)
                                    ABCollectWindow.colletors.RemoveAt(i);
                    }, "Remove UnChoosed");
                });
                DrawHorizontal(() => {
                    Button((bo) =>
                    {
                        if (bo)
                            for (int i = ABCollectWindow.colletors.Count - 1; i >= 0; i--)
                                ABCollectWindow.colletors[i].Selected = true;
                    }, "Choose All");
                    Button((bo) =>
                    {
                        if (bo)
                            for (int i = ABCollectWindow.colletors.Count - 1; i >= 0; i--)
                                ABCollectWindow.colletors[i].Selected = false;
                    }, "UnChooseAll");
                });
                Button((bo) =>
                {
                    if (bo) {
                        for (int i = ABCollectWindow.colletors.Count-1; i >=0 ; i--)
                        {
                            if (string.IsNullOrEmpty( ABCollectWindow.colletors[i].searchPath) || 
                            !Directory.Exists(ABCollectWindow.colletors[i].searchPath))
                            {
                                ABCollectWindow.colletors.RemoveAt(i);
                            }
                        }
                        ABCollectInfoIO.Save(ABCollectWindow.colletors);
                    }
                }, "Save",Height(30));

            }, rect);
        }
    }

}
